﻿using System;
using Newtonsoft.Json;

namespace ICommonLibrary.Json {

    public static class JsonConvertExtension {

        public static T DeserializeObject<T>(string json, Func<T> returnIfFailed) {
            if (string.IsNullOrEmpty(json)) {
                return returnIfFailed();
            }

            try {
                return JsonConvert.DeserializeObject<T>(json);
            }
            catch(Exception e) {
                return returnIfFailed();
            }
        }
         
    }
}